//引入进度条相关的环境
import NProgress from "nprogress"
import "nprogress/nprogress.css"


import axios from "axios";
import store from "store"
const axiosins = axios.create({
    baseURL:"/api",
    timeout:15000
})
// 添加请求拦截器
axiosins.interceptors.request.use(function (config) {
    //开启进度条
    NProgress.start();
    //给所有请求加上userTempId
    config.headers["userTempId"] = store.state.user.userTempId;

    //从localstorage中拿出token 放到请求头中
    const token = window.localStorage.getItem("shp_token")
    if(token){
        config.headers["token"] = token
    }
    return config;
});

// 添加响应拦截器
axiosins.interceptors.response.use(function (response) {
    //关闭进度条
    NProgress.done();
    return response.data;
}, function (error) {
    //关闭进度条
    NProgress.done();
    return Promise.reject(error);
});


export default axiosins;